package com.Cychat.commons.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Auther: 刘博文
 * Date: 2025/10/31:14:03
 * Description: OSS配置类
 */
@Configuration
public class OssConfig {

    @Value("${aliyun.oss.endpoint:}")
    private String endpoint;

    @Value("${aliyun.oss.keyid:}")
    private String accessKeyId;

    @Value("${aliyun.oss.keysecret:}")
    private String accessKeySecret;

    @Value("${aliyun.oss.bucketname:}")
    private String bucketName;

    @Bean
    public OSS ossClient() {
        // 只有当配置了必要的参数时才创建OSS客户端
        if (!endpoint.isEmpty() && !accessKeyId.isEmpty() && !accessKeySecret.isEmpty()) {
            return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        }
        return null;
    }

    public String getEndpoint() {
        return endpoint;
    }

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public String getAccessKeySecret() {
        return accessKeySecret;
    }

    public String getBucketName() {
        return bucketName;
    }
}
